import { useLocation } from 'react-router-dom';
import { menuItems, flatMenuItems, defaultRoute } from '@/router/config';

// 路由相关的工具函数
export const useRouteHelpers = () => {
  const location = useLocation();
  
  // 根据当前路径获取选中的菜单项
  const getSelectedKeys = () => {
    const currentItem = flatMenuItems.find(item => item.path === location.pathname);
    return currentItem ? [currentItem.key] : [defaultRoute.key];
  };

  // 获取默认展开的菜单项
  const getDefaultOpenKeys = () => {
    const currentItem = flatMenuItems.find(item => item.path === location.pathname);
    if (currentItem) {
      const parentGroup = menuItems.find(group => 
        group.children?.some(child => child.key === currentItem.key)
      );
      return parentGroup ? [parentGroup.key] : [];
    }
    return ['basics'];
  };

  return {
    getSelectedKeys,
    getDefaultOpenKeys,
  };
};

// 导出配置
export { menuItems, flatMenuItems, routeConfigs, defaultRoute } from '@/router/config';
export { AppRoutes } from '@/router/routes'; 